package xyz.liuyuhe.StudySpring.ch7.cglibproxy;

import org.springframework.cglib.proxy.Enhancer;

public class CglibProxyMain {
    public static void main(String[] args) {
        DBQuery query = createProxy(new DBQuery());
        System.out.println(query.request("123"));
    }

    @SuppressWarnings("unchecked")
    private static <T> T createProxy(T target) {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(target.getClass());
        enhancer.setCallback(new DBQueryInterceptor(target));
        
        return (T)enhancer.create();
    }
}
